<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require 'application/libraries/fb/facebook.php';
class Face extends MX_Controller {

	function __construct(){
		parent::__construct();
		$this->template->write('title','Source Admin Apps facebook');
		$this->template->write('meta_keywords','Source Admin Apps facebook');
		$this->template->write('meta_description','Source Admin Apps facebook');
		$this->template->write('meta_image','');
		$this->template->write('meta_video','');
	}
	
	/*-------------------------------------- FrontEnd --------------------------------------*/
	function index(){
		$data = array();
		// $str_search = strpos($_SERVER['QUERY_STRING'],'state=');
		// if($str_search!==false && $_SERVER['HTTP_HOST']=='climaxi.com'){
			// header('Location:'. FB_REDIRECT_PAGE);
			// exit;
		// }
	
		// if(isset($_SERVER['HTTP_REFERER']) && ($_SERVER['HTTP_REFERER']=='http://www.facebook.com/dialog/permissions.request' || $_SERVER['HTTP_REFERER']=='https://www.facebook.com/dialog/permissions.request')){
			// header('Location:'. FB_REDIRECT_PAGE);
			// exit;
		// }
		
		// if(isset($_SERVER['HTTP_REFERER'])){
			// $str_pos = strpos($_SERVER['HTTP_REFERER'],'apps.facebook.com');
			// if($str_pos!==false){
				// print "<script type='text/javascript'>top.location.href='".FB_REDIRECT_PAGE."';</script>";
				// exit;
			// }
		// }		

		// if($this->input->post('signed_request')){
			// $_SESSION['signed_request'] = $this->input->post('signed_request');
		// }
		
		// $facebook = new Facebook(array('appId'  => FB_APP_ID, 'secret' => FB_APP_SECRET));
		// $user_id = $facebook->getUser();
		// $signed_request = $facebook->getSignedRequest();
		
		// if(isset($signed_request['user_id'])){
			// if($signed_request['page']['liked']==1){
				// if(!empty($signed_request['app_data']))
				// {
					// $app_data = $signed_request['app_data'];
					// $app_data = json_decode($app_data);
				// }
			
				// if(isset($app_data->id) && is_numeric($app_data->id)){ 
					// $url = PATH_URL.'contest/contest_detail/'. $app_data->id;
					// header("Location: ".$url);
					// exit();
				// }
				
				// if(isset($app_data->link)){
					// switch($app_data->link)
					// {
						// case 'the-le':
							// $url_share = 'the_le';
							// break;
						// case 'danh-sach-thang-giai':
							// $url_share = 'winner';
							// break;
						// case 'danh-sach-bai-thi':
							// $url_share = 'contest_list';
							// break;
					// }
				// }else{
						// $url_share = '';
				// }
			
				// if(isset($url_share) && $url_share != ''){
					// $link_share = PATH_URL.'contest'.$url_share;
					// header("Location: ".$link_share); 
					// exit();
				// }
				//$users = $facebook->api('/me'); 	
				//$this->session->set_userdata('ss_fb_id',$users['id']);
				header('Location: '.PATH_URL.'contest/contest_register');		
				exit();
			// }else{
				// $this->no_like();
			// }
		// }else{
			// $loginUrl = $facebook->getLoginUrl(array('scope' => 'read_stream,email,user_birthday,publish_stream','redirect_uri' => FB_REDIRECT_PAGE));
			// print '<script type="text/javascript">top.location="'.$loginUrl.'"</script>';
			// exit;
		// }
	}
	
	function no_like()
	{
		$data = array();
		$data['meta_video'] = '';
		$data['meta_image'] = '';
		$data['meta_description'] = 'Source Admin Apps facebook';
		$data['meta_keywords'] = 'Source Admin Apps facebook';
		$data['title'] = 'Source Admin Apps facebook';
		$this->load->view('FRONTEND/no_like',$data);
	}
}